import router from "../router";
import { createPinia } from "pinia";
import Lazyload from "./components/LazyLoad/index.vue";
import Swiper from './components/Swiper/index.vue';
import SwiperItem from './components/Swiper/SwiperItem.vue';
import Main from './components/Main/index.vue';
import Pannel from './components/Pannel/index.vue';
import lazy from "./directives/lazyLoad";

import Overlay from './components/Define/Overlay/index.vue';
import Loading from "./components/Define/Loading/index.vue";
import Toast from './components/Define/Toast/index.vue';
import From from './components/Define/From/index.vue';
import Label from './components/Define/Label/index.vue';
import DropDown from './components/Define/Dropdown/index.vue';
import Select from './components/Define/Select/index.vue';
import Input from './components/Define/Input/index.vue';
import Password from './components/Define/Password/index.vue';
import FormItem from './components/Define/From/FormItem.vue';

import { reactive } from "vue";

export default class Plugins {
  constructor(options = {}) {
    this.options = options;
  }

  //  注册
  install(app, options) {
    installDirectives.call(this, app, options);
    installComponents.call(this, app, options);

    const pinia = createPinia();
    
    app.use(router);
    app.use(pinia);
  }
}

//  注册全局组件
function installComponents(app) {
  app.component('LazyLoad', Lazyload);
  app.component('Swiper', Swiper);
  app.component('SwiperItem', SwiperItem);
  app.component('Main', Main);
  app.component('Pannel', Pannel);
  app.component('Overlay', Overlay);
  app.component('Loading', Loading);
  app.component('Toast', Toast);
  app.component('d-from', From);
  app.component('d-label', Label);
  app.component('DropDown', DropDown);
  app.component('Select', Select);
  app.component('d-input', Input);
  app.component('d-password', Password);
  app.component('d-form-item', FormItem);
}

//  注册全局指令
function installDirectives(app) {
  app.directive('lazy', lazy( this.options.lazyLoad ));
}